<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2018/8/1 0001
 * Time: 下午 6:18
 */

namespace app\admin\model;


use think\Model;

class ManagerGoodsList extends Model
{
    public static function checkStockByid($id,$num){
        $db = self::get($id)->toArray();
        $rest = $db['stock'] - $db['sale'];
        if ($rest<$num){
            return true;
        }else{
            return false;
        }
    }

    /**释放库存
     * @param array $data
     * @return bool
     * @throws \think\Exception
     */
    public static function reStock($data=[]){
        if (!empty($data)){
            foreach ($data as $v){
                self::where('id',$v['id'])->setDec('sale',$v['num']);
            }
            return true;
        }else{
            return false;
        }
    }

    /**减库存
     * @param array $data
     * @return bool
     * @throws \think\Exception
     */
    public static function deStock($data=[]){
        if (!empty($data)){
            foreach ($data as $v){
                self::where('id',$v['mgl_id'])->setInc('sale',$v['num']);
            }
            return true;
        }else{
            return false;
        }
    }
}